// aenpc.txt
// Like basicnpc, but can also project a damaging AE. 
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Type of AE
//		0 - fire, does 1-6 * level
//		1 - cold, does 1-8 * level
//		2 - energy, does 1-10 * level
//		3 - slow
//		4 - debuff
//		5 - daze
//		6 - charm
//		7 - fear
//		8 - acid
//      9 - lightning aura
//		10 - poison
// 		11 - cleave (1-8 dam per level)
//   Cell 4 - Range of AE, Left at default of 4 if 0
//   Cell 5 - Number of state when talked to. Plays default text if 0.
//   Cell 6 - % chance of using AE, defaults to 50% if left at 0

begincreaturescript;

variables;

short i,target;
short last_abil;
short ae_chance = 50;
short ae_range = 4;
short damage_warn = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Restoration Pylon");
	set_level(ME,30);
	set_boss_level(ME,2);
	set_char_unkillable(ME,1);
	set_walk_speed(ME,0);
	
	set_flag(get_memory_cell(1),get_memory_cell(2),0);
	
	last_abil = get_current_tick();

	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; 
	if (gf(101,4) > 0)
		set_attitude(ME,4);
	if (get_attitude(ME) < 10)
		end();
	
	if ((get_health(ME) < get_max_health(ME) / 4) && (gf(get_memory_cell(1),get_memory_cell(2)) == 0)) {
		set_flag(get_memory_cell(1),get_memory_cell(2),1);
		print_str_color("A pylon has become heavily damaged. All of its power begins to",3);
		print_str_color("  leak out through the cracks in its side.",3);
		last_abil = get_current_tick();

		if (gf(42,14) == 0) {
			sf(42,14,1);
			begin_talk_mode(12);
			}
			
		end();
		}
		else {
			if ((damage_warn == 0) && (get_health(ME) < get_max_health(ME) / 2)) {
				damage_warn = 1;
				print_str_color("This pylon is starting to crack. Keep hitting it, and it will",3);
				print_str_color("  soon explode.",3);
				}
			}


	if ((is_combat()) && (gf(get_memory_cell(1),get_memory_cell(2)) > 0) &&
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	

			status_nearby(-20,ae_range,9,0);
			status_nearby(-20,ae_range,11,0);
			status_nearby(-20,ae_range,12,0);
			status_nearby(-20,ae_range,13,0);
			status_nearby(-20,ae_range,14,0);
			status_nearby(-20,ae_range,15,0);
			status_nearby(-20,ae_range,16,0);
			status_nearby(-20,ae_range,18,0);
			status_nearby(-20,ae_range,19,0);

		  	place_particle_num(ME,1,4,8);
			print_named_str(ME,"leaks out a cloud of energy.");
			pc_heard_sound_delay(179,250);						
	  		create_missile_spiral(147,40,ae_range,2);
	  		damage_nearby(get_ran(1,200,250),ae_range,1,0);
			status_nearby(5,ae_range,20,0);


		last_abil = get_current_tick();
		end();
		}
	if (tick_difference(last_abil,get_current_tick()) <= 0)
		end_combat_turn();
		
break;

beginstate TALKING_STATE;
	begin_talk_mode(13);
break;